package com.stone.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stone.bean.AppResponse;
import com.stone.bean.BasePage;
import com.stone.mapper.TestMapper;
import com.stone.entity.TestDO;
import com.stone.service.TestService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * test
 */
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, TestDO> implements TestService {

    @Resource
    private TestMapper testMapper;

    @Override
    public AppResponse findAllByName(String name) {
        List<TestDO> list = this.baseMapper.selectList(new QueryWrapper<TestDO>().eq("name", name));
        return AppResponse.success().setRecords(list);
    }

    @Override
    public AppResponse findAll(String name) {
        List<TestDO> all = testMapper.findAll(name);
        return AppResponse.success().setRecords(all);
    }

    @Override
    public AppResponse query(BasePage dto) {
        Page<TestDO> testDOPage = new Page<>(dto.getPage(), dto.getPageSize());
        IPage<TestDO> page = this.page(testDOPage, new QueryWrapper<TestDO>().orderByDesc("id"));
        return AppResponse.success().setRecords(page.getRecords()).setTotal(page.getTotal());
    }
}
